import 'package:sil_utils_package/sil_utils_package.dart';
/**
 * 电站设备的具体信息（三方获取到的）
 */

class PowerStationEntity {
  String? battery_state;
  String? pv_state;
  String? power_grid_state;
  String? load_state;

  String? power_grid_data;

  /// 剩余电量
  String? surplus_power;

  /// 当前功率
  String? real_power;

  String? stationType;
  String? one_sell_electric_money;
  String? real_power_bwfz;
  String? equipmentSelection;
  String? real_power_fzgl;
  String? runTime;
  String? id;

  /// 电站名称+在线状态
  String? ps_name;
  String? battery_data;
  String? load_data;
  String? powerPrice;
  String? one_ga_revenue;

  /// 发电量
  String? one_generation;

  /// 买电量
  String? one_pay_electric;

  /// 买电量
  String? one_sell_electric;
  String? one_pay_electric_money;

  String? moneyUnit;
  String? pv_data;

  /// 获取电站温度，余额信息
  String? batteryVoltage;
  String? pv_one;
  String? pv_two_current;
  String? outputCurrent;
  String? dcdc_temperature;
  String? ambient_temperature;
  String? electricityConsumption;
  String? electricityCost;
  String? inverter_temperature;
  String? pv_three;
  String? pv_two;
  String? bms_temperature;
  String? pv_four;

  /// 基础信息
  String? stored_total;
  String? use_electric_total;
  String? diesel_oil;
  String? forest;
  String? generation_total;
  String? create_time;
  String? co2;
  String? coal;
  String? money_total;

  String? bmsTemperature;
  PowerStationEntity({
    this.battery_state,
    this.power_grid_data,
    this.surplus_power,
    this.real_power,
    this.stationType,
    this.one_sell_electric_money,
    this.real_power_bwfz,
    this.equipmentSelection,
    this.one_pay_electric,
    this.pv_state,
    this.one_pay_electric_money,
    this.real_power_fzgl,
    this.runTime,
    this.id,
    this.ps_name,
    this.power_grid_state,
    this.load_state,
    this.one_sell_electric,
    this.battery_data,
    this.load_data,
    this.powerPrice,
    this.one_ga_revenue,
    this.one_generation,
    this.moneyUnit,
    this.pv_data,
    this.batteryVoltage,
    this.pv_one,
    this.pv_two_current,
    this.outputCurrent,
    this.dcdc_temperature,
    this.ambient_temperature,
    this.electricityConsumption,
    this.electricityCost,
    this.inverter_temperature,
    this.pv_three,
    this.pv_two,
    this.bms_temperature,
    this.pv_four,
    this.stored_total,
    this.use_electric_total,
    this.diesel_oil,
    this.forest,
    this.generation_total,
    this.create_time,
    this.co2,
    this.coal,
    this.money_total,
  });
  PowerStationEntity.fromJson(Map<String, dynamic> json) {
    /// 基础信息
    stored_total = SilEntityLog.handleString(json, 'stored_total');
    use_electric_total = SilEntityLog.handleString(json, 'use_electric_total');
    diesel_oil = SilEntityLog.handleString(json, 'diesel_oil');
    forest = SilEntityLog.handleString(json, 'forest');
    generation_total = SilEntityLog.handleString(json, 'generation_total');
    create_time = SilEntityLog.handleString(json, 'create_time');
    co2 = SilEntityLog.handleString(json, 'co2');
    coal = SilEntityLog.handleString(json, 'coal');
    money_total = SilEntityLog.handleString(json, 'money_total');

    battery_state = SilEntityLog.handleString(json, 'battery_state');
    power_grid_data = SilEntityLog.handleString(json, 'power_grid_data');
    surplus_power = SilEntityLog.handleString(json, 'surplus_power');
    real_power = SilEntityLog.handleString(json, 'real_power');
    stationType = SilEntityLog.handleString(json, 'stationType');
    one_sell_electric_money =
        SilEntityLog.handleString(json, 'one_sell_electric_money');
    real_power_bwfz = SilEntityLog.handleString(json, 'real_power_bwfz');
    equipmentSelection = SilEntityLog.handleString(json, 'equipmentSelection');
    one_pay_electric = SilEntityLog.handleString(json, 'one_pay_electric');
    pv_state = SilEntityLog.handleString(json, 'pv_state');
    one_pay_electric_money =
        SilEntityLog.handleString(json, 'one_pay_electric_money');
    real_power_fzgl = SilEntityLog.handleString(json, 'real_power_fzgl');
    runTime = SilEntityLog.handleString(json, 'runTime');
    id = SilEntityLog.handleString(json, 'id');
    ps_name = SilEntityLog.handleString(json, 'ps_name');
    power_grid_state = SilEntityLog.handleString(json, 'power_grid_state');
    load_state = SilEntityLog.handleString(json, 'load_state');
    one_sell_electric = SilEntityLog.handleString(json, 'one_sell_electric');
    battery_data = SilEntityLog.handleString(json, 'battery_data');
    load_data = SilEntityLog.handleString(json, 'load_data');
    powerPrice = SilEntityLog.handleString(json, 'powerPrice');
    one_ga_revenue = SilEntityLog.handleString(json, 'one_ga_revenue');
    one_generation = SilEntityLog.handleString(json, 'one_generation');
    moneyUnit = SilEntityLog.handleString(json, 'moneyUnit');
    pv_data = SilEntityLog.handleString(json, 'pv_data');

    batteryVoltage = SilEntityLog.handleString(json, 'batteryVoltage');
    pv_one = SilEntityLog.handleString(json, 'pv_one');
    pv_two_current = SilEntityLog.handleString(json, 'pv_two_current');
    outputCurrent = SilEntityLog.handleString(json, 'outputCurrent');
    dcdc_temperature = SilEntityLog.handleString(json, 'dcdc_temperature');
    ambient_temperature =
        SilEntityLog.handleString(json, 'ambient_temperature');
    electricityConsumption =
        SilEntityLog.handleString(json, 'electricityConsumption');
    electricityCost = SilEntityLog.handleString(json, 'electricityCost');
    inverter_temperature =
        SilEntityLog.handleString(json, 'inverter_temperature');
    pv_three = SilEntityLog.handleString(json, 'pv_three');
    pv_two = SilEntityLog.handleString(json, 'pv_two');
    bms_temperature = SilEntityLog.handleString(json, 'bms_temperature');
    pv_four = SilEntityLog.handleString(json, 'pv_four');
  }
  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();

    /// 基础信息
    data['stored_total'] = this.stored_total;
    data['use_electric_total'] = this.use_electric_total;
    data['diesel_oil'] = this.diesel_oil;
    data['forest'] = this.forest;
    data['generation_total'] = this.generation_total;
    data['create_time'] = this.create_time;
    data['co2'] = this.co2;
    data['coal'] = this.coal;
    data['money_total'] = this.money_total;

    /// 电站信息
    data['battery_state'] = this.battery_state;
    data['power_grid_data'] = this.power_grid_data;
    data['surplus_power'] = this.surplus_power;
    data['real_power'] = this.real_power;
    data['stationType'] = this.stationType;
    data['one_sell_electric_money'] = this.one_sell_electric_money;
    data['real_power_bwfz'] = this.real_power_bwfz;
    data['equipmentSelection'] = this.equipmentSelection;
    data['one_pay_electric'] = this.one_pay_electric;
    data['pv_state'] = this.pv_state;
    data['one_pay_electric_money'] = this.one_pay_electric_money;
    data['real_power_fzgl'] = this.real_power_fzgl;
    data['runTime'] = this.runTime;
    data['id'] = this.id;
    data['ps_name'] = this.ps_name;
    data['power_grid_state'] = this.power_grid_state;
    data['load_state'] = this.load_state;
    data['one_sell_electric'] = this.one_sell_electric;
    data['battery_data'] = this.battery_data;
    data['load_data'] = this.load_data;
    data['powerPrice'] = this.powerPrice;
    data['one_ga_revenue'] = this.one_ga_revenue;
    data['one_generation'] = this.one_generation;
    data['moneyUnit'] = this.moneyUnit;
    data['pv_data'] = this.pv_data;

    data['batteryVoltage'] = this.batteryVoltage;
    data['pv_one'] = this.pv_one;
    data['pv_two_current'] = this.pv_two_current;
    data['outputCurrent'] = this.outputCurrent;
    data['dcdc_temperature'] = this.dcdc_temperature;
    data['ambient_temperature'] = this.ambient_temperature;
    data['electricityConsumption'] = this.electricityConsumption;
    data['electricityCost'] = this.electricityCost;
    data['inverter_temperature'] = this.inverter_temperature;
    data['pv_three'] = this.pv_three;
    data['pv_two'] = this.pv_two;
    data['bms_temperature'] = this.bms_temperature;
    data['pv_four'] = this.pv_four;
    return data;
  }

  /// 光伏工作的状态流程图
  String get pvStateGifImgPath {
    String gifImgPath = 'imgs/home/index1.png';
    if (this.pv_state == '-1') {
      gifImgPath = 'imgs/home/index_new_gif1.gif';
    } else if (this.pv_state == '1') {
      gifImgPath = 'imgs/home/index_new_gif11.gif';
    }
    return gifImgPath;
  }

  /// 电网工作的状态流程图
  String get powerGridStateGifImgPath {
    String gifImgPath = 'imgs/home/index2.png';
    if (this.power_grid_state == '-1') {
      gifImgPath = 'imgs/home/index_new_gif22.gif';
    } else if (this.power_grid_state == '1') {
      gifImgPath = 'imgs/home/index_new_gif2.gif';
    }
    return gifImgPath;
  }

  /// 电池工作的状态流程图
  String get batteryStateGifImgPath {
    String gifImgPath = 'imgs/home/index3.png';
    if (this.battery_state == '-1') {
      gifImgPath = 'imgs/home/index_new_gif33.gif';
    } else if (this.battery_state == '1') {
      gifImgPath = 'imgs/home/index_new_gif3.gif';
    }
    return gifImgPath;
  }

  /// 负载工作的状态流程图
  String get loadStateStateGifImgPath {
    String gifImgPath = 'imgs/home/index4.png';
    if (this.load_state == '-1') {
      gifImgPath = 'imgs/home/index_new_gif4.gif';
    } else if (this.load_state == '1') {
      gifImgPath = 'imgs/home/index_new_gif44.gif';
    }
    return gifImgPath;
  }

  /// 储能设备是否工作
  bool get isRuning {
    if (this.pv_state == '1' ||
        this.power_grid_state == '1' ||
        this.battery_state == '1' ||
        this.load_state == '1') {
      return true;
    }
    return false;
  }

  /// 电池温度
  String get bmsTemperatureStr {
    return (SilTools.stringIsEmpty(this.bms_temperature))
        ? '0.0'
        : this.bms_temperature!;
  }

  /// 逆变器内部温度
  String get inverterTemperatureStr {
    return (SilTools.stringIsEmpty(this.inverter_temperature))
        ? '0.0'
        : this.inverter_temperature!;
  }

  /// 发电量
  String get oneGenerationStr {
    return (SilTools.stringIsEmpty(this.one_generation))
        ? '0.0'
        : this.one_generation!;
  }

  /// 买电量
  String get onePayElectricStr {
    return (SilTools.stringIsEmpty(this.one_pay_electric))
        ? '0.0'
        : this.one_pay_electric!;
  }

  /// 用电量
  String get electricityConsumptionStr {
    return (SilTools.stringIsEmpty(this.electricityConsumption))
        ? '0.0'
        : this.electricityConsumption!;
  }

  /// 卖电量
  String get oneSellElectricStr {
    return (SilTools.stringIsEmpty(this.one_sell_electric))
        ? '0.0'
        : this.one_sell_electric!;
  }

  /// 发电收益
  String get oneGaRevenueStr {
    return (SilTools.stringIsEmpty(this.one_ga_revenue))
        ? '0.0'
        : this.one_ga_revenue!;
  }

  /// 买电费用
  String get onePayElectricMoneyStr {
    return (SilTools.stringIsEmpty(this.one_pay_electric_money))
        ? '0.0'
        : this.one_pay_electric_money!;
  }

  /// 卖电收益
  String get oneSellElectricMoneyStr {
    return (SilTools.stringIsEmpty(this.one_sell_electric_money))
        ? '0.0'
        : this.one_sell_electric_money!;
  }

  /// 用电费用
  String get electricityCostStr {
    return (SilTools.stringIsEmpty(this.electricityCost))
        ? '0.0'
        : this.electricityCost!;
  }

  /// 光伏功率
  String get pvDataStr {
    return (SilTools.stringIsEmpty(this.pv_data)) ? '0' : this.pv_data!;
  }

  /// 电网功率
  String get powerGridDataStr {
    return (SilTools.stringIsEmpty(this.power_grid_data))
        ? '0'
        : this.power_grid_data!;
  }

  /// 电池功率
  String get batteryDataStr {
    return (SilTools.stringIsEmpty(this.battery_data))
        ? '0'
        : this.battery_data!;
  }

  /// 负载功率
  String get loadDataStr {
    return (SilTools.stringIsEmpty(this.load_data)) ? '0' : this.load_data!;
  }

  /// 并网负载功率
  String get onGridLoadStr {
    return (SilTools.stringIsEmpty(this.real_power_bwfz))
        ? '0'
        : this.real_power_bwfz!;
  }

  /// 离网负载功率
  String get offGridLoadStr {
    return (SilTools.stringIsEmpty(this.real_power_fzgl))
        ? '0'
        : this.real_power_fzgl!;
  }

  /// 剩余电量进度条（圆圈）的颜色
  String get surplusPowerCircleHexColor {
    String hexColorStr = "#c81410";

    String surplus_power = this.surplus_power ?? "0";
    if (surplus_power == '') {
      surplus_power = '0';
    }
    double surplusPower = double.parse(surplus_power);

    if (20 <= surplusPower && surplusPower <= 40) {
      hexColorStr = "#e1b92e";
    } else if (surplusPower > 40) {
      hexColorStr = "#09bcd6";
    }

    return hexColorStr;
  }

  /// 当前功率百分比
  double get realPowerPer {
    double per = 0;
    String real_power = this.real_power ?? "0";
    if (real_power == '') {
      real_power = '0';
    }
    if (this.equipmentSelection == 1) {
      //实时功率
      per = double.parse(real_power) / 1000;
    } else {
      per = double.parse(real_power) / 500;
    }

    return per;
  }

  /// 当前功率进度条（圆圈）的颜色
  String get realPowerPerCircleHexColor {
    String hexColorStr = "#09bcd6";

    double per = this.realPowerPer;

    if (70 <= per && per <= 80) {
      hexColorStr = "#e1b92e";
    } else if (per >= 80) {
      hexColorStr = "#c81410";
    }

    return hexColorStr;
  }

  /// 输出功能
  String get outputCurrentStr {
    return (SilTools.stringIsEmpty(this.outputCurrent))
        ? '0'
        : this.outputCurrent!;
  }

  /// 输出功能
  String get pvTwoCurrentStr {
    return (SilTools.stringIsEmpty(this.pv_two_current))
        ? '0'
        : this.pv_two_current!;
  }

  /// 电池电压
  String get batteryVoltageStr {
    return (SilTools.stringIsEmpty(this.batteryVoltage))
        ? '0'
        : this.batteryVoltage!;
  }
}
